from django.shortcuts import render
from rest_framework.generics import ListAPIView
from home.models import NavModel, BannerModel
from fuguang.utils import constants
from home.serializers import NavSerializer, BannerSerializer
from fuguang.utils.views import CacheListApiView


# # 导航的视图
# # 顶部导航
# class NavHeardListViews(ListAPIView):
#     queryset = NavModel.objects.filter(is_deleted=False, is_show=True, position=constants.NAV_HEARD).order_by('-id')[:constants.NAV_HEARD_SIZE]
#     serializer_class = NavSerializer
#
#
# # 底部导航
# class NavFooterListViews(ListAPIView):
#     queryset = NavModel.objects.filter(is_deleted=False, is_show=True, position=constants.NAV_FOOTER).order_by('-id')[:constants.NAV_FOOTER_SIZE]
#     serializer_class = NavSerializer
#
#
# # 轮播图视图
# class BannerListApiView(ListAPIView):
#     queryset = BannerModel.objects.filter(is_show=True, is_deleted=False).order_by('-id')[:constants.BANNER_SIZE]
#     serializer_class = BannerSerializer


# 导航的视图
# 顶部导航
class NavHeardListViews(CacheListApiView):
    queryset = NavModel.objects.filter(is_deleted=False, is_show=True, position=constants.NAV_HEARD).order_by('-id')[:constants.NAV_HEARD_SIZE]
    serializer_class = NavSerializer


# 底部导航
class NavFooterListViews(CacheListApiView):
    queryset = NavModel.objects.filter(is_deleted=False, is_show=True, position=constants.NAV_FOOTER).order_by('-id')[:constants.NAV_FOOTER_SIZE]
    serializer_class = NavSerializer


# 轮播图视图
class BannerListApiView(CacheListApiView):
    queryset = BannerModel.objects.filter(is_show=True, is_deleted=False).order_by('-id')[:constants.BANNER_SIZE]
    serializer_class = BannerSerializer
